import random
import time
from Tkinter import *
axoaxonic=1
axosomatic=0

class Vue(object):
    def __init__(self, x,y):
        self.root=Tk()
        self.canevas=Canvas(self.root,width=x,height=y)
        self.canevas.pack()
        self.drawBrain(b)
        self.root.mainloop()
        
    def drawBrain(self,b):
        n=10
        for h in b.regions:
            for i in h.neurones:
                self.canevas.create_oval(i.x,i.y,i.x+n,i.y+n,fill="green",outline="green")
                for j in i.dendrites:
                    self.canevas.create_line(j.x+i.x,j.y+i.y,i.x,i.y,fill="blue")
                    m=2
                    for k in j.synapses:
                        x=i.x+(j.x-50)+(k.x-5)
                        y=i.y+(j.y-50)+(k.y-5)
#                        self.canevas.create_rectangle(x,y,x+n,y+n,fill="red",outline="red")
                        self.canevas.create_oval(x,y,x+m,y+m,fill="purple",outline="red",width=0)
                for j in i.axones:
                    self.canevas.create_line(j.x+i.x,j.y+i.y,i.x,i.y,fill="orange")
#                    for k in j.synapses:
#                        x=i.x+(j.x-50)+(k.x-5)
#                        y=i.y+(j.y-50)+(k.y-5)
#                        self.canevas.create_rectangle(x,y,x+n,y+n,fill="darkgreen",outline="darkgreen")

class Brain(object):
    def __init__(self,r,n):
        self.regions=[]
        t=0
        for i in range(r):
            self.regions.append(Region(n))
            t+=1
            print t
            
class Region(object):
    def __init__(self,n):
        self.neurones=[]
        for i in range(n):
            self.neurones.append(Neurone())
    def connecteNeurones(self):
        for i in self.neurones:
            for j in i.dendrites:
                pass
            
class Neurone(object):
    def __init__(self):
        self.x=random.randrange(1000)
        self.y=random.randrange(1000)
        self.z=random.randrange(1000)
        self.dendrites=[]
        self.axones=[]
        self.neuro=0
        self.fire=10
        self.growNeurones(Dendrite,self.dendrites)
        self.growNeurones(Axone,self.axones)
        
    def growNeurones(self,sorte,liste):
        n=random.randrange(10,20)
        for i in range(n):
            liste.append(sorte(self))
            
class Dendrite(object):
    def __init__(self,parent):
        self.synapses=[]
        self.modulateur=0
        self.x=random.randrange(100)-50
        self.y=random.randrange(100)-50
        self.z=random.randrange(100)-50
        self.growSynapses()
    def growSynapses(self):
        n=random.randrange(20,50)
        for i in range(n):
            self.synapses.append(Synapse(self,1))
        
class Axone(object):
    def __init__(self, parent):
        self.parent=parent
        self.x=random.randrange(100)
        self.y=random.randrange(100)
        self.z=random.randrange(100)
        self.synapses=[]
        self.growSynapses()
    
    def growSynapses(self):
        n=random.randrange(20,50)
        for i in range(n):
            self.synapses.append(Synapse(self,0))
        
class Synapse(object):
    def __init__(self, parent,sorte):
        self.parent=parent
        self.sorte=sorte
        self.x=random.randrange(10)
        self.y=random.randrange(10)
        self.z=random.randrange(10)
        
def calcObjets(b):
    n=0
    for h in b.regions:
        for i in h.neurones:
            for j in i.dendrites:
                for k in j.synapses:
                    n= n+1
                n=n+1
            for j in i.axones:
                for k in j.synapses:
                    n= n+1
                n=n+1
            n=n+1
        n=n+1
    n+=1
    return n
if __name__ == '__main__':
    print time.time()
    b=Brain(1,10)
    print time.time()
    c=Brain(0,30)
    print time.time()
    n=calcObjets(b)
    m=calcObjets(c)
    print n, m
    v=Vue(1000,1000)
